package com.irdstudio.efp.edoc.service.impl;

import java.util.List;
import java.util.Objects;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.edoc.service.bo.FileExportListVO;
import com.irdstudio.efp.edoc.service.dao.FileExportListDao;
import com.irdstudio.efp.edoc.service.domain.FileExportList;
import com.irdstudio.efp.edoc.service.facade.FileExportListService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>ServiceImpl: 导出文件清单				<p>
 * @author ligm
 * @date 2020-01-08
 */
@Service("fileExportListService")
public class FileExportListServiceImpl implements FileExportListService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(FileExportListServiceImpl.class);

	@Autowired
	private FileExportListDao fileExportListDao;
	
	/**
	 * 新增操作
	 */
	public int insertFileExportList(FileExportListVO inFileExportListVo) {
		logger.debug("当前新增数据为:"+ inFileExportListVo.toString());
		int num = 0;
		try {
			FileExportList fileExportList = new FileExportList();
			beanCopy(inFileExportListVo, fileExportList);
			num = fileExportListDao.insertFileExportList(fileExportList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(FileExportListVO inFileExportListVo) {
		logger.debug("当前删除数据条件为:"+ inFileExportListVo);
		int num = 0;
		try {
			FileExportList fileExportList = new FileExportList();
			beanCopy(inFileExportListVo, fileExportList);
			num = fileExportListDao.deleteByPk(fileExportList);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inFileExportListVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(FileExportListVO inFileExportListVo) {
		logger.debug("当前修改数据为:"+ inFileExportListVo.toString());
		int num = 0;
		try {
			FileExportList fileExportList = new FileExportList();
			beanCopy(inFileExportListVo, fileExportList);
			num = fileExportListDao.updateByPk(fileExportList);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inFileExportListVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public FileExportListVO queryByPk(FileExportListVO inFileExportListVo) {
		
		logger.debug("当前查询参数信息为:"+ inFileExportListVo);
		try {
			FileExportList queryFileExportList = new FileExportList();
			beanCopy(inFileExportListVo, queryFileExportList);
			FileExportList queryRslFileExportList = fileExportListDao.queryByPk(queryFileExportList);
			if (Objects.nonNull(queryRslFileExportList)) {
				FileExportListVO outFileExportListVo = beanCopy(queryRslFileExportList, new FileExportListVO());
				logger.debug("当前查询结果为:"+ outFileExportListVo.toString());
				return outFileExportListVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public int updateByFileName(FileExportListVO fileExportListVO) {
		logger.debug("当前修改数据为:"+ fileExportListVO.toString());
		int num = 0;
		try {
			FileExportList fileExportList = new FileExportList();
			beanCopy(fileExportListVO, fileExportList);
			num = fileExportListDao.updateByFileName(fileExportList);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ fileExportListVO +"修改的数据条数为:"+ num);
		return num;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileExportListVO> queryAllOwner(FileExportListVO fileExportListVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<FileExportListVO> list = null;
		try {
			List<FileExportList> fileExportLists = fileExportListDao.queryAllOwnerByPage(fileExportListVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ fileExportLists.size());
			pageSet(fileExportLists, fileExportListVo);
			list = (List<FileExportListVO>) beansCopy(fileExportLists, FileExportListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileExportListVO> queryAllCurrOrg(FileExportListVO fileExportListVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<FileExportList> fileExportLists = fileExportListDao.queryAllCurrOrgByPage(fileExportListVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+fileExportLists.size());
		List<FileExportListVO> list = null;
		try {
			pageSet(fileExportLists, fileExportListVo);
			list = (List<FileExportListVO>) beansCopy(fileExportLists, FileExportListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<FileExportListVO> queryAllCurrDownOrg(FileExportListVO fileExportListVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<FileExportList> fileExportLists = fileExportListDao.queryAllCurrDownOrgByPage(fileExportListVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ fileExportLists.size());
		List<FileExportListVO> list = null;
		try {
			pageSet(fileExportLists, fileExportListVo);
			list = (List<FileExportListVO>) beansCopy(fileExportLists, FileExportListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	@Override
	public List<FileExportListVO> queryAllByCondition(FileExportListVO fileExportListVo) {
		logger.debug("当前查询数据信息的参数信息为:" + fileExportListVo.toString());
		List<FileExportList> fileExportLists = fileExportListDao.queryAllByConditon(fileExportListVo);
		logger.debug("当前查询数据信息的结果集数量为:"+ fileExportLists.size());
		List<FileExportListVO> list = null;
		try {
			if(Objects.isNull(fileExportLists) || fileExportLists.size() == 0){
				return null;
			}
			list = (List<FileExportListVO>) beansCopy(fileExportLists, FileExportListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
}
